using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace OA.BLL
{
    public class WebSite:Base
    {
        private DAL.WebSite dal = null;
        public WebSite()
        {
            isession = DB_help.NHibernateHelper.GetCurrentSession(DefaultDataBase);
            dal = new DAL.WebSite(isession);
        }

        public Common.Result Add(Model.WebSite value)
        {
            Common.Result ret = new Common.Result(false, 0, "修改失败");
            if (dal.GetModel(value.Code) != null)
            {
                ret.message = "[资源编号]已经存在";
                return ret;
            }
            ret = dal.Add(value);
            return ret;
        }

        public Common.Result Update(Model.WebSite value)
        {
            Common.Result ret = new Common.Result(false, 0, "修改失败");
            var dalvalue = dal.GetModel(value.Code);
            if (dalvalue == null)
            {
                ret.success = false;
                ret.count = 0;
                ret.message = "数据不存在,无法修改";
                return ret;
            }

            dalvalue.Name = value.Name;
            dalvalue.Address = value.Address;
            dalvalue.IconCls = value.IconCls;
            dalvalue.IsShow = value.IsShow;
            dalvalue.Sort = value.Sort;
            ret = dal.Update(dalvalue);
            return ret;
        }

        public Common.Result Delete(string ids)
        {
            var ret=dal.Delete(ids);
            return ret;
        }

        public Model.WebSite GetModel(string id)
        {
            return dal.GetModel(id);
        }

        public IList<Model.WebSite> Get(string where, string orderby, int start, int length,params object[] ps)
        {
            return dal.Get(where, orderby, start, length, ps);
        }

        public int GetCount(string where, params object[] ps)
        {
            return dal.GetCount(where, ps);
        }
    }
}
